#define _CRT_SECURE_NO_WARNINGS 1
//选择排序
#include<stdio.h>
void Swap(int* x, int* y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}
void SelectSort(int* a,int size)
{
	//遍历找最大和最小的下标
	//最小的放左边  最大的放右边
	
	int left = 0;
	int right = size - 1;
	while (right > left)
	{
		int max = left;
		int min = left;
		for (int i = left+1; i <= right; i++)
		{
			if (a[i] > a[max])
			{
				max = i;
			}
			if (a[i] < a[min])
			{
				min = i;
			}
		}
		Swap(&a[min],&a[left]);
		if (max == left)
		{
			max = min;
		}
		Swap(&a[max], &a[right]);
		left++;
		right--;
	}
	

}
int main()
{
	int a[] = { 9,1,2,5,7,4,8,6,3,5 };
	SelectSort(a, sizeof(a) / sizeof(int));
	for (int  i = 0; i < sizeof(a) / sizeof(int); i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}